package com.yc.cloud.socket.utils;


import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.date.DateUnit;
import org.springframework.stereotype.Component;

import javax.websocket.Session;

/**
 * @author 杨智杰
 * @since 2021/9/22 14:09
 */
@Component
public class SocketSessionCacheUtil {

    public static Long SESSION_TIME_OUT = 300L;

    public static TimedCache<String, Session> sessionCache = CacheUtil.newTimedCache(SESSION_TIME_OUT * DateUnit.SECOND.getMillis());

    public static void put(String key, Session session) {
        sessionCache.put(key, session);
    }

    public static Session get(String key) {
        return sessionCache.get(key);
    }

    public static void remove(String key) {
        sessionCache.remove(key);
    }

}